package com.hh.usersystem.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hh.baseframework.exception.MessageException;
import com.hh.baseframework.util.check.Check;
import com.hh.baseframework.util.dto.ExtTree;
import com.hh.system.service.impl.BaseService;
import com.hh.system.util.base.BaseServiceAction;
import com.hh.system.util.model.ReturnModel;
import com.hh.usersystem.bean.usersystem.HhXtYh;
import com.hh.usersystem.service.impl.UserService;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class Actionuser extends BaseServiceAction<HhXtYh> implements
		ModelDriven<HhXtYh> {
	private HhXtYh hhXtYh = new HhXtYh();
	private String orgs;
	private String roles;
	@Autowired
	private UserService userService;
	private String oldPassword;

	@Override
	public BaseService<HhXtYh> getService() {
		return userService;
	}

	public HhXtYh getModel() {
		return hhXtYh;
	}

	public void queryPagingData() {
		this.returnResult(userService.queryPagingData(hhXtYh,
				this.getPageRange(), orgs, roles));
	}

	public void queryPagingDataCombox() {
		if (Check.isNoEmpty(this.hhXtYh.getId())) {
			this.returnResult(userService.queryItemsByIdsStr(hhXtYh.getId()));
		} else {
			this.returnResult(userService.queryPagingData(hhXtYh,
					this.getPageRange(), null, null));
		}
	}

	public void queryPagingDataList() {
		this.returnResult(userService.queryPagingData(hhXtYh,
				this.getPageRange(), null, null));
	}

	public void queryOnLinePagingData() {
		this.getResultMap().putAll(
				userService.queryOnLinePagingData(hhXtYh, this.getPageRange()));
		this.returnResult();
	}

	public void deleteOnLineByIds() {
		userService.deleteOnLineByIds(this.getIds());
	}

	public void save() {
		try {
			HhXtYh hhXtYh = userService.save(this.hhXtYh);
			this.getResultMap().put("object", hhXtYh);
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void updatePassWord() {
		try {
			userService.updatePassWord(this.hhXtYh, oldPassword);
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void vdlzhOnly() {
		boolean result = userService.checkVdlzhOnly(hhXtYh);
		this.returnResult(result);
	}

	public void findObjectById() {
		HhXtYh hhXtYh = userService.findObjectById(this.hhXtYh.getId());
		this.returnResult(hhXtYh);
	}

	public void deleteByIds() {
		userService.deleteByIds(this.getIds());
	}

	public void insertYhOrg() {
		userService.insertYhOrg(this.getParamsMap());
	}

	public void deleteYhOrg() {
		userService.deleteYhOrg(this.getParamsMap());
	}

	public void queryCylxrs() {
		List<HhXtYh> hhXtYhs = userService.queryCylxrs();
		this.returnResult(hhXtYhs);
	}

	public void queryCylxrTree() {
		List<ExtTree> hhXtYhs = userService.queryCylxrTree();
		this.returnResult(hhXtYhs);
	}

	public void addCylxr() {
		try {
			userService.addCylxr(this.getParamsMap().get("cylxrid"));
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void deleteCylxr() {
		try {
			userService.deleteCylxr(this.getParamsMap().get("cylxrid"));
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void queryUserByOrcCode() {
		List<HhXtYh> hhXtYhList = userService.queryUserByOrcCode(request
				.getParameter("code"));
		this.returnResult(hhXtYhList);
	}

	public void queryUserByRole() {
		List<HhXtYh> hhXtYhList = userService.queryUserByRole(request
				.getParameter("roleId"));
		this.returnResult(hhXtYhList);
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public String getOrgs() {
		return orgs;
	}

	public void setOrgs(String orgs) {
		this.orgs = orgs;
	}

	public String getRoles() {
		return roles;
	}

	public void setRoles(String roles) {
		this.roles = roles;
	}

}
